#pragma once

#include "stdafx.h"

class CCamera;
class CHeightMap;
class CQuadTree;

class CTerrain
{
public:
	CTerrain();
	CTerrain(int cxTerrain,int czTerrain);
	~CTerrain();
private:
	int						m_cxTerrain;
	int						m_czTerrain;

	D3DXVECTOR3				m_vScale;
	D3DXMATRIX				m_mtxWorld;
//	D3DXMATRIX				m_mtxTexture;

	CHeightMap				*m_pHeightMap;
	
	CQuadTree				*m_pQuadTree;
	int						m_nQuards;
	LPDIRECT3DVERTEXBUFFER9 m_pVertexBuffer;
	LPDIRECT3DINDEXBUFFER9  m_pIndexBuffer;

	int						m_nTriangles;

//	int						m_nMaterial;

//	int						m_nTextures;
	LPDIRECT3DTEXTURE9		m_pTexture1;
	LPDIRECT3DTEXTURE9		m_pTexture2;
	D3DMATERIAL9			*m_pMaterial;

public:
	void Build(LPDIRECT3DDEVICE9 pD3DDevice, DWORD dwOptions = D3DXMESH_MANAGED);
	void Render(LPDIRECT3DDEVICE9 pD3DDevice, CCamera *pCamera);

private:
	void GenerateIndex();
};
